package com.example.weiba_app;

import android.content.res.AssetManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;



public class MainActivity extends FragmentActivity {
	
	private Fragment[] mFragments;
	private RadioGroup bottomRg;
	private FragmentManager fragmentManager;
	private FragmentTransaction fragmentTransaction;
	private RadioButton rbOne, rbTwo, rbThree, rbFour;
	private static AssetManager assetManager;	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		mFragments = new Fragment[4];
		fragmentManager = getSupportFragmentManager();
		mFragments[0] = fragmentManager.findFragmentById(R.id.fragement_even);
		mFragments[1] = fragmentManager.findFragmentById(R.id.fragement_circle);
		mFragments[2] = fragmentManager.findFragmentById(R.id.fragement_friend);
		mFragments[3] = fragmentManager.findFragmentById(R.id.fragement_set);
		fragmentTransaction = fragmentManager.beginTransaction().hide(mFragments[0])
				.hide(mFragments[1]).hide(mFragments[2])
				.hide(mFragments[3]);
		fragmentTransaction.show(mFragments[0]).commit();
		setFragmentIndicator();
		assetManager = getAssets();
	}
	public static AssetManager getAssetManager() {
		return assetManager;
	}
	private void setFragmentIndicator() {

		bottomRg = (RadioGroup) findViewById(R.id.bottpm_nav);
		rbOne = (RadioButton) findViewById(R.id.radioButton_even);
		rbTwo = (RadioButton) findViewById(R.id.radioButton_circle);
		rbThree = (RadioButton) findViewById(R.id.radioButton_friend);
		rbFour= (RadioButton) findViewById(R.id.radioButton_set);
//		rbOne.setOnTouchListener(this);
//		rbTwo.setOnTouchListener(this);
//		rbTwo.setOnTouchListener(this);
//		rbFour.setOnTouchListener(this);
//		rbFive.setOnTouchListener(this);
		bottomRg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				fragmentTransaction = fragmentManager.beginTransaction().hide(mFragments[0])
						.hide(mFragments[1]).hide(mFragments[2]).hide(mFragments[3]);
				switch (checkedId) {
				case R.id.radioButton_even:
					fragmentTransaction.show(mFragments[0]).commit();
					break;
				case R.id.radioButton_circle:
					fragmentTransaction.show(mFragments[1]).commit();
					break;

				case R.id.radioButton_friend:
					fragmentTransaction.show(mFragments[2]).commit();
					break;
				case R.id.radioButton_set:
					fragmentTransaction.show(mFragments[3]).commit();
					break;
				default:
					break;
				}
			}
		});
//		rbOne.setOnTouchListener(this);
//		rbTwo.setOnTouchListener(this);
//		rbTwo.setOnTouchListener(this);
//		rbFour.setOnTouchListener(this);
//		rbFive.setOnTouchListener(this);
	}				
}
